package parse_and_index.search.inverted;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;

import parse_and_index.model.Document;
import parse_and_index.model.Page;

public class Result implements Comparable<Object> {

	  private float				 score;
	  private Document			  currentDocument;
	  private final ArrayList<Page> pages;

	  public Result(final float s, final Document d, final ArrayList<Page> pgs) {
			score = s;
			currentDocument = d;
			pages = pgs;
	  }

	  public Document getDocument() {
			return currentDocument;
	  }

	  /* returns right justified char string representation of score with d digits */
	  public String getScore(final int d, final DecimalFormat form) {
			String temp;
			String result = "";
			Float f;
			f = new Float(score);
			temp = form.format(f);
			for (int i = 0; i < (d - temp.length()); i++) {
				  result += " ";
			}
			return result + temp;
	  }

	  public ArrayList<Page> getPages() {
			return pages;
	  }

	  public void put(final float s, final Document d) {
			score = s;
			currentDocument = d;
	  }

	  @Override
	  public int compareTo(final Object r) {
			final Result currentResult = (Result) r;
			if (currentResult.score > score) { return -1; }
			if (currentResult.score < score) { return 1; }
			return 0;
	  }

	  @Override
	  public String toString() {
			Collections.reverse(pages);
			String ret = "Result: ";
			ret += pages.get(0);
			for (int i = 1; i < pages.size(); i++) {
				  ret += ", " + pages.get(i);
			}
			return Float.toString(score) + " : " + currentDocument + " : " + ret;
	  }
}